home *** CD-ROM | disk | FTP | other *** search
/ NOVA - For the NeXT Workstation / NOVA - For the NeXT Workstation.iso / Documents / NeXTAnswers / appkit.732 < prev    next >
Text File  |  1992-02-06  |  2KB  |  56 lines

  1. {\rtf0\ansi{\fonttbl\f0\fnil Times-Roman;\f2\fmodern Courier;\f1\fswiss Helvetica;}
  2. \paperw12180
  3. \paperh9140
  4. \margl120
  5. \margr120
  6. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f0\b0\i0\ul0\fs28 NXImage NXBitmapImageRep setDataRetained useRepresentation\
  7. \
  8.  
  9. \fi-440\li440 Q:  I have allocated an instance of NXImage and an instance of NXBitmapImageRep.  I then tell the NXImage to use the rep instance, like this:\
  10. \
  11.  
  12. \f2\fs24\fi1000 #import <appkit/NXImage.h>\
  13. #import <appkit/NXBitmapImageRep.h>\
  14. \
  15. NXRect originalSize;\
  16. id myRep, myImage;\
  17. int bitsPerPixel;\
  18. \
  19. myRep = [[NXBitmapImageRep alloc] initFromFile: filename];\
  20. [myRep getSize: &originalSize];\
  21. myImage = [[NXImage alloc] initSize: &originalSize];\
  22. [myImage useRepresentation: myRep];\
  23.  
  24. \f0\fs28\fi-440 \
  25.  
  26. \fi0 Then, later in my application I query the rep instance (as follows) and the query fails because myRep is nil!  Why is this?\
  27.  
  28. \fi-440 \
  29.  
  30. \f2\fs24\fi1000 bitsPerPixel = [myRep bitsPerPixel]; /* this fails -- myRep is nil ! */\
  31.  
  32. \f0\fs28\fi0\li0 \
  33.  
  34. \fi-440\li440 A:  This is not a bug.  Once you have “given” the NXBitmapImageRep instance to NXImage (by calling 
  35. \f2\fs24 useRepresentation:
  36. \f0\fs28 ) then the NXImage "owns" that rep and can do what it wishes with it.   (This is also true for any class of rep instance, not just NXBitmapImageRep)  What the NXimage typically does is to turn that representation into an NXCachedImageRep and then free the NXBitmapImageRep.  To prevent this behavior do a 
  37. \f2\fs24 setDataRetained:YES
  38. \f0\fs28  on the NXImage instance.  The 
  39. \f2\fs24 setDataRetained:
  40. \f0\fs28  method defaults to NO.  The NXImage then will not free the NXBitmapImageRep.  For example, to correct the above example, add the following line prior to calling 
  41. \f2\fs24 useRepresentation:
  42. \f0\fs28 \
  43. \
  44.  
  45. \f2\fs24\fi1000 [myImage setDataRetained:YES];
  46. \f0\fs28\fi-440 \
  47.  
  48. \fi0\li0 \
  49. \
  50. QA732\
  51. \
  52. Not valid for 1.0\
  53. Valid for 2.0\
  54. \
  55.  
  56.